package cn.demarcia.coco.ui.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.viewpagerindicator.IconPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import cn.demarcia.coco.AppConfig;
import cn.demarcia.coco.ui.fragment.NewsViewPager;


public class NewsViewPagerAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
    protected List<Fragment> pagers = new ArrayList<>();
    private Context context;
    private static final String[] TYPE = new String[]{
            AppConfig.TOP, AppConfig.SOCIETY, AppConfig.INNER, AppConfig.INTERNATIONAL,
            AppConfig.ENTERTAINMENT, AppConfig.MILITARY, AppConfig.PHYSICAL,
            AppConfig.SCIENCE, AppConfig.FINANCE, AppConfig.FASHION};


    public NewsViewPagerAdapter(Context context, FragmentManager fm) {
        super(fm);
        this.context = context;
        pagers.add(NewsViewPager.getInstance(NewsViewPager.TOP));
        pagers.add(NewsViewPager.getInstance(NewsViewPager.SOCIETY));
        pagers.add(NewsViewPager.getInstance(NewsViewPager.INNER));
        pagers.add(NewsViewPager.getInstance(NewsViewPager.INTERNATIONAL));
        pagers.add(NewsViewPager.getInstance(NewsViewPager.ENTERTAINMENT));
        pagers.add(NewsViewPager.getInstance(NewsViewPager.MILITARY));
        pagers.add(NewsViewPager.getInstance(NewsViewPager.PHYSICAL));
        pagers.add(NewsViewPager.getInstance(NewsViewPager.SCIENCE));
        pagers.add(NewsViewPager.getInstance(NewsViewPager.FINANCE));
        pagers.add(NewsViewPager.getInstance(NewsViewPager.FASHION));
    }

    @Override
    public Fragment getItem(int position) {
        return pagers.get(position);
    }

    @Override
    public int getIconResId(int index) {
        return 0;
    }


    @Override
    public int getCount() {
        return TYPE.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return TYPE[position];
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        return super.instantiateItem(container, position);
    }

}